﻿using Microsoft.Extensions.Configuration;
using MiniFox.Web;
using System.Collections.Specialized;
using System.Configuration;
using System.Net.Mime;
using System.Text;

namespace MiniFox.Net.Configurations
{
    /// <summary>
    /// 
    /// </summary>
    public sealed class ServiceSetting : IServiceSetting
    {
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationKeyName("name")]
        public string Name
        {
            get;set;
        }

        /// <summary>
        /// 
        /// </summary>
        [ConfigurationKeyName("uri")]
        public string Uri
        {
            get;set;
        }

        /// <summary>
        /// 
        /// </summary>
        [ConfigurationKeyName("contentType")]
        public string ContentType
        {
            get; set;
        } = MediaTypeNames.Application.Json;
        /// <summary>
        /// url参数
        /// </summary>    
        [ConfigurationKeyName("urlParameters")]
        public Dictionary<string, string> UrlParameters
        {
            get; set;
        } = new ();
        /// <summary>
        /// 请求携带的header
        /// </summary>
        [ConfigurationKeyName("headers")]
        public Dictionary<string, string> Headers
        {
            get;set;
        } = new();
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationKeyName("contentEncoding")]
        public string ContentEncodingName
        {
            get; set;
        }
        /// <summary>
        /// 
        /// </summary>
        public Encoding ContentEncoding
        {
            get
            {
                return string.IsNullOrWhiteSpace(this.ContentEncodingName) ? Encoding.UTF8 : Encoding.GetEncoding(this.ContentEncodingName);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationKeyName("timeout")]
        public int Timeout
        {
            get; set;
        } = 60;
    }
}
